var debugPage


/* eslint-disable */
let idTmr;
// 判断浏览器是否为IE
const getExplorer = () => {
	let explorer = window.navigator.userAgent;
	//ie
	if (explorer.indexOf("MSIE") >= 0) {
		return 'ie';
	}
	//firefox

	else if (explorer.indexOf("Firefox") >= 0) {
		return 'Firefox';
	}
	//Chrome
	else if (explorer.indexOf("Chrome") >= 0) {
		return 'Chrome';
	}
	//Opera
	else if (explorer.indexOf("Opera") >= 0) {
		return 'Opera';
	}
	//Safari
	else if (explorer.indexOf("Safari") >= 0) {
		return 'Safari';
	}
}

const exportToExcel = (data, name) => {
	// 判断是否为IE
	if (getExplorer() == 'ie') {
		tableToIE(data, name)
	} else {
		tableToNotIE(data, name)
	}
}

const Cleanup = () => {
	window.clearInterval(idTmr);
}

// ie浏览器下执行
const tableToIE = (data, name) => {
	let curTbl = data;
	let oXL = new ActiveXObject("Excel.Application");

	//创建AX对象excel
	let oWB = oXL.Workbooks.Add();
	//获取workbook对象
	let xlsheet = oWB.Worksheets(1);
	//激活当前sheet
	let sel = document.body.createTextRange();
	sel.moveToElementText(curTbl);
	//把表格中的内容移到TextRange中
	sel.select;
	//全选TextRange中内容
	sel.execCommand("Copy");
	//复制TextRange中内容
	xlsheet.Paste();
	//粘贴到活动的EXCEL中

	oXL.Visible = true;
	//设置excel可见属性

	try {
		let fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
	} catch (e) {
		print("Nested catch caught " + e);
	} finally {
		oWB.SaveAs(fname);

		oWB.Close(savechanges = false);
		//xls.visible = false;
		oXL.Quit();
		oXL = null;
		// 结束excel进程，退出完成
		window.setInterval("Cleanup();", 1);
		idTmr = window.setInterval("Cleanup();", 1);
	}
}

// 非ie浏览器下执行
const tableToNotIE = (function () {
	// 编码要用utf-8不然默认gbk会出现中文乱码
	let uri = 'data:application/vnd.ms-excel;base64,',
		template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta charset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table border="1">{table}</table></body></html>',
		base64 = function (s) {
			return window.btoa(unescape(encodeURIComponent(s)));
		},

		format = (s, c) => {
			return s.replace(/{(\w+)}/g,
				(m, p) => {
					return c[p];
				})
		}
	return (table, name) => {
		let ctx = {
			worksheet: name,
			table
		}

		//创建下载
		let link = document.createElement('a');
		link.setAttribute('href', uri + base64(format(template, ctx)));
		link.setAttribute('download', name);
		link.click();
	}
})()

/**
 * 生成一个随机pkid,如果没有参数就是默认32位
 * @param {Object} len
 */
function randomPkid(len) {
	if(!len) {
		len = 32
	}
	var randomstring = ""
	var charlist = "0123456789qwertyuiopasdfghjklzxcvbnm"
	for(var i = 0; i < len; i++) {
		randomstring += charlist[Math.ceil(Math.random() * 35)]
	}
	return randomstring
}

var CookiesTools = (function() {
	var bean = {}
	bean.get = function(name) {
		var list = document.cookie.split(";")
		var value = undefined
		list.forEach(function(item) {
			item = item.trim()
			var nameend = item.indexOf('=')
			var cname = item.substring(0, nameend)
			var cvalue = item.substring(nameend + 1, item.length)
			if(cname == name) {
				value = cvalue
			}
		})
		return value
	}
	return bean
})()
//string格式化
String.prototype.format = String.prototype.f = function() {
	var s = this
	var i = arguments.length
	while(i--) {
		s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i])
	}
	return s
}
/**
 * 从某个字符以后开始截取字符串，不包括被截取的字符
 */
String.prototype.subByFirstChar = function(findChar) {
	return this.substr(this.indexOf(findChar) + 1)
}
/**
 * 从某个字符以后开始截取字符串，不包括被截取的字符
 */
String.prototype.subByLastChar = function(findChar) {
	return this.substr(this.lastIndexOf(findChar) + 1)
}
/**
 * 截取从开始到某个最后找到的字符串的部分
 */
String.prototype.subToLastChar = function(findChar) {
	return this.substr(0, this.lastIndexOf(findChar))
}
/**
 * 截取从开始到某个最后找到的字符串的部分
 */
String.prototype.subToFirstChar = function(findChar) {
	return this.substr(0, this.indexOf(findChar))
}
/**
 * 将首字母大写
 */
String.prototype.upperCaseFirstChar = function() {
	if(this.length == 0) {
		return this
	}
	var firstChar = this[0].toUpperCase()
	return firstChar + this.substr(1)
}
/**
 * 删除
 */
Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
}

/**
 * 深拷贝
 */
Array.prototype.copy = function() {
	return copy(this)
}

function uniq(array) {
	var temp = []; //一个新的临时数组
	for(var i = 0; i < array.length; i++) {
		if(temp.indexOf(array[i]) == -1) {
			temp.push(array[i]);
		}
	}
	return temp;
}
/**
 * 数组去重
 */
Array.prototype.distinct = function() {
	/*let result = []
	let obj = {}
	for (let i of this) {
		if (!obj[i]) {
			result.push(i)
			obj[i] = 1
		}
	}*/
	return uniq(this)
}

/**
 * 如果有值就返回值，没有就返回指定默认值
 */
function getValueIfNoNull(value, defaultValue) {
	return value == undefined ? defaultValue : value
}

function copy(item) {
	try {
		return JSON.parse(JSON.stringify(item))
	} catch(e) {
		console.error(e.stack)
	}
}
/**
 * 插入
 * @param {Object} index
 * @param {Object} item
 */
Array.prototype.insert = function(index, item) {
	this.splice(index, 0, item);
}
/**
 * 数组合并
 * @param {Object} array
 */
Array.prototype.addAll = function(array) {
	if(array == undefined) {
		return this
	}
	for(var i = 0, len = array.length; i < len; i++) {
		this.push(array[i])
	}
	return this
}
/**
 * 数据清空
 */
Array.prototype.clear = function() {
	var _this = this
	this.splice(0, this.length)
}

// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子：
// (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.format = function(fmt) { //author: meizz
	var o = {
		"M+": this.getMonth() + 1, //月份
		"d+": this.getDate(), //日
		"h+": this.getHours(), //小时
		"m+": this.getMinutes(), //分
		"s+": this.getSeconds(), //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds() //毫秒
	};
	if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for(var k in o) {
		if(new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		};
	}
	return fmt;
}
/**
 * 获取格式化yyyy/MM/dd的日期字符串
 */
Date.prototype.formatByDate = function(interval) {
	if(interval == undefined) {
		interval = '/'
	}
	return this.getFullYear() + interval + (this.getRealMonth() < 10 ? '0' : '') + this.getRealMonth() + interval + (this
		.getDate() < 10 ? '0' : '') + this.getDate()
}
/**
 * 获取格式化的日期字符串
 * @param {Object} interval yyyy+interval+MM+interval+dd HH:mm:ss 默认是/
 */
Date.prototype.formatByTime = function(interval) {
	return this.formatByDate(interval) + " " + (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' + (this.getMinutes() <
		10 ? '0' : '') + this.getMinutes() + ":" + (this.getSeconds() < 10 ? '0' : '') + this.getSeconds()
}

/**
 * 获取格式化的日期字符串
 * @param {Object} interval yyyy+interval+MM+interval+dd HH:mm:ss:sss 默认是/
 */
Date.prototype.formatByMillisecond = function(interval) {
	return this.formatByDate(interval) + " " + (this.getHours() < 10 ? '0' : '') + this.getHours() + ':' + (this.getMinutes() <
		10 ? '0' : '') + this.getMinutes() + ":" + (this.getSeconds() < 10 ? '0' : '') + this.getSeconds() + ":" + this.getMilliseconds()
}
/**
 * 获取格式化的日期字符串
 * @param {Object} interval yyyy+interval+MM,默认是/
 */
Date.prototype.formatByMonth = function(interval) {
	if(interval == undefined) {
		interval = '/'
	}
	return this.getFullYear() + interval + (this.getRealMonth() < 10 ? '0' : '') + this.getRealMonth()
}
/**
 * 获取格式化的日期字符串
 * @param {Object} interval yyyy+interval+MM,默认是/
 */
Date.prototype.formatByYear = function(interval) {
	if(interval == undefined) {
		interval = '/'
	}
	return this.getFullYear() + interval + (this.getRealMonth() < 10 ? '0' : '')
}

/**
 * 真实月份
 */
Date.prototype.getRealMonth = function() {
	return this.getMonth() + 1
}
/**
 * 获取日期
 * @param {Object} num   0今天,-1昨天,1，明天
 * @param {Object} str   分割方式
 * return yyyy + str + MM + str + dd,默认yyyy-MM-dd
 */
function getDay(num, str) {
	if(undefined == str) {
		str = "-"
	}
	var today = new Date();
	var nowTime = today.getTime();
	var ms = 24 * 3600 * 1000 * num;
	today.setTime(parseInt(nowTime + ms));
	var oYear = today.getFullYear();
	var oMoth = (today.getMonth() + 1).toString();
	if(oMoth.length <= 1) {
		oMoth = '0' + oMoth;
	}
	var oDay = today.getDate().toString();
	if(oDay.length <= 1) {
		oDay = '0' + oDay;
	}
	return oYear + str + oMoth + str + oDay;
}

/**
 * 毫秒值转为时分秒列表
 * @param {Object} mss
 */
function formatDuring(mss) {
	if(mss < 1000) {
		return [0, 0, 0, 0]
	}
	var days = parseInt(mss / (1000 * 60 * 60 * 24));
	var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
	var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
	var seconds = parseInt((mss % (1000 * 60)) / 1000);
	return [days, hours, minutes, seconds]
}
/**
 * 获取周一和周七的时间
 * @param {int} AddWeekCount为0代表当前周   为-1代表上一个周   为1代表下一个周以此类推
 * @param {Date} currentDate 查询的时间
 */
function getWeekStartAndEnd(AddWeekCount, currentDate) {
	var startStop = new Array();
	var millisecond = 1000 * 60 * 60 * 24;
	currentDate = new Date(currentDate.getTime() + (millisecond * 7 * AddWeekCount));
	var week = currentDate.getDay();
	var month = currentDate.getDate();
	var minusDay = week != 0 ? week - 1 : 6;
	var currentWeekFirstDay = new Date(currentDate.getTime() - (millisecond * minusDay));
	var currentWeekLastDay = new Date(currentWeekFirstDay.getTime() + (millisecond * 6));
	startStop.push(currentWeekFirstDay.format("yyyy-MM-dd"));
	startStop.push(currentWeekLastDay.format("yyyy-MM-dd"));
	return startStop;
}
/**  
 * 获得相对当月AddMonthCount个月的起止日期  
 * AddMonthCount为0 代表当月 为-1代表上一个月  为1代表下一个月 以此类推
 * currentDate 要获取的时间
 * ***/
function getMonthStartAndEnd(AddMonthCount, currentDate) {
	var startStop = new Array();
	var month = currentDate.getMonth() + AddMonthCount;
	if(month < 0) {
		var n = parseInt((-month) / 12);
		month += n * 12;
		currentDate.setFullYear(currentDate.getFullYear() - n);
	}
	currentDate = new Date(currentDate.setMonth(month));
	var currentMonth = currentDate.getMonth();
	var currentYear = currentDate.getFullYear();
	var currentMonthFirstDay = new Date(currentYear, currentMonth, 1);
	var currentMonthLastDay = new Date(currentYear, currentMonth + 1, 0);
	//添加至数组    
	startStop.push(currentMonthFirstDay.format("yyyy-MM-dd"));
	startStop.push(currentMonthLastDay.format("yyyy-MM-dd"));
	return startStop;
}
/**
 * 获取今天属于本月第几周
 * @param {Object} a 年
 * @param {Object} b 月
 * @param {Object} c 日
 */
function getMonthWeek(a, b, c) {
	var date = new Date(a, parseInt(b) - 1, c),
		w = date.getDay(),
		d = date.getDate();
	if(w == 0) {
		w = 7;
	}
	var config = {
		getMonth: date.getMonth() + 1,
		getYear: date.getFullYear(),
		getWeek: Math.ceil((d + 6 - w) / 7),
	}
	return config;
};
/**
 * 
 * @param {Object} mss
 */

function formatDuringToString(mss) {
	var list = formatDuring(mss)
	return '{0} 天 {1} 小时 {2} 分 {3} 秒'.format(list[0], list[1], list[2], list[3])
}

/**
 * 过滤树型数据
 */
function filterTreeRecursive(list, keepMethod) {
	if(isempty(list)) {
		return []
	}
	//debugger
	//先过滤下一级
	for(var i = 0, len = list.length; i < len; i++) {
		var item = list[i]
		if(item.hasOwnProperty("next")) {
			item.next = filterTreeRecursive(item.next, keepMethod)
		}
	}
	//再过滤当前层级
	list = list.filter(keepMethod)
	return list
}

/**
 * 判断一个点值是否是废的或者空的
 */
function isnull(value) {
	if(value == undefined) {
		return true;
	}
	if(value < -1.1 && value > -1.2) {
		return true;
	}
	return false;
}
/**
 * 判断是不是未定义或者为空,只用于判断undefined或者长度为0的数组或者空的对象
 * @param {Object} value
 */
function isempty(value) {
	return value == undefined || value.length == 0 || JSON.stringify(value) == "{}"
}
/**
 * 处理历史数据数据
 * @param {Object} data
 * @param {Object} deal,一个方法,会传进来value和keyname,然后要返回一个结果
 */
function dealHistory(data, deal) {
	var ndata = []
	var keys = Object.keys(data)
	keys = keys.filter(function(e) {
		return e.substring(0, 5) == 'value'
	})
	keys = keys.sort(function(a, b) {
		var a1 = a.substr(5)
		var b1 = b.substr(5)
		return a1 - b1
	})
	for(var i = 0, len = keys.length; i < len; i++) {
		var keyname = keys[i]
		ndata.push(deal(data[keyname], keyname))
	}
	return ndata
}
/**
 * 遍历对象的所有属性
 * @param {Object} callback
 */
function eachObject(data, callback) {
	if(data == undefined) {
		return
	}
	var keys = Object.keys(data)
	for(var i = 0, len = keys.length; i < len; i++) {
		var item = keys[i]
		callback(data[item], item, i)
	}
}
/**
 * 合并两个数组并且去重和排序
 * @param {Object} baseorder
 * @param {Object} neworder 加在后面
 * @param {Object} key id字段
 * @param {Object} sort 排序方法
 */
function concatArray(baseorder, neworder, key, sort) {
	//获取id列表
	var ids = {};
	if(baseorder == undefined && neworder == undefined) {
		return []
	}
	if(baseorder == undefined) {
		return neworder
	}
	if(neworder == undefined) {
		return baseorder
	}
	baseorder.forEach(function(ele) {
		ids[ele[key]] = 1;
	});
	//去重复
	neworder = neworder.filter(function(item) {
		return ids[item[key]] == undefined;
	});
	var newarray = baseorder.concat(neworder)
	//排序
	if(sort) {
		newarray = newarray.sort(sort)
	}
	return newarray
}
/**
 * 按时间排序,默认倒序
 * @param {Object} key 字段
 * @param {Object} asc 不传就是近的在前,传就是早的在前
 */
function sortByTime(key, asc) {
	return function(a, b) {
		var datea = a[key].replace(/-/g, "/")
		var dateb = b[key].replace(/-/g, "/")
		if(asc) {
			return new Date(datea).getTime() - new Date(dateb).getTime()
		} else {
			return new Date(dateb).getTime() - new Date(datea).getTime()
		}
	}
}
/**
 * 递归查找并且计算sort,找不到就返回undefined
 * @param {Object} list 数据列表
 * @param {Object} findMethod 判断当前是不是查找的对象的方法,接受一个参数返回true或者false
 * @param {Object} countMethod 计算sort的方式,会传两个参数,一个是当前找到的对象,一个是对象下一个,不一定有值
 */
function calculateSort(list, findMethod, countMethod) {
	if(isempty(list)) {
		return
	}
	var targetItem = undefined
	for(var i = 0, len = list.length; i < len; i++) {
		var item = list[i]
		if(targetItem == undefined && findMethod(item)) {
			//找到了当前级
			targetItem = item
			if(i == len - 1) {
				//最后一个,直接返回
				return countMethod(item)
			}
		} else if(targetItem != undefined) {
			//有下级,sort取平均数
			return countMethod(targetItem, item)
		}
	}
	//没在当前级找到,准备递归
	for(var i = 0, len = list.length; i < len; i++) {
		var item = list[i]
		var sort = calculateSort(item.next, findMethod, countMethod)
		if(sort != undefined) {
			return sort
		}
	}
}

/**
 * 异步加载html文件到指定的id元素
 * @param {Object} path
 * @param {Object} callback
 * @param {Object} targetid 模板id,不传默认是loadhtml
 */
function loadHtml(path, callback, targetid) {
	if(targetid == undefined) {
		targetid = 'loadhtml'
	}
	Vue.http.get(path, {}, {
		emulateJSON: true
	}).then(function(respon) {
		var ele = document.getElementById(targetid)
		respon = respon.body;
		var temp = ele.innerHTML + respon
		ele.innerHTML = temp
		if(callback) {
			callback()
		}
	}, function(respon) {});
}
/**
 * 加载js文件
 * @param {Object} path
 */
function loadJS(path) {
	var myScript = document.createElement("script");
	myScript.type = "text/javascript";
	myScript.src = path;
	document.body.appendChild(myScript);
}
/**
 * 保留N位小数,返回是个字符串!!
 * @param {Object} digital
 * @param {Object} len
 */
function cutDigital(digital, len) {
	if(len == undefined) {
		len = 2;
	}
	if(len < 0) {
		return 0;
	}
	var res = (Math.round(digital * Math.pow(10, len))) / Math.pow(10, len)
	if(isNaN(res)) {
		return
	}
	res += ''
	//补全0到位数达标
	var now = 0
	if(res.indexOf('.') != -1) {
		now = res.substr(res.indexOf('.') + 1).length
	} else {
		res += '.'
	}
	for(var i = now; i < len; i++) {
		res += '0'
	}
	return res;
}
/**
 * 返回是个字符串!!
 * @param {Object} digital
 * @param {Object} len
 */
function cutDigitalFloor(digital, len) {
	if(len == undefined) {
		len = 2;
	}
	if(len < 0) {
		return 0;
	}
	var res = (Math.floor(digital * Math.pow(10, len))) / Math.pow(10, len)
	if(isNaN(res)) {
		return
	}
	res += ''
	//补全0到位数达标
	var now = 0
	if(res.indexOf('.') != -1) {
		now = res.substr(res.indexOf('.') + 1).length
	} else {
		res += '.'
	}
	for(var i = now; i < len; i++) {
		res += '0'
	}
	return res;
}
/**
 * 获取对象的类型
 * @param {Object} obj
 */
function getClass(obj) {
	var classname = Object.prototype.toString.call(obj)
	classname = classname.substr(classname.indexOf(' ') + 1)
	classname = classname.substr(0, classname.length - 1)
	return classname
}
/**
 * 为所有元素均分宽度
 * @param {Object} maxWidth 最大宽度
 * @param {Object} sons 需要修改宽度的子元素,id字段或者object对象二选一,具有字段needChange的是会变的,weight为权重
 */
function measureWidth(maxWidth, sons) {
	//已经用了 宽度
	var usew = 0
	var needChange = []
	var totalWeight = 0
	sons.forEach(function(item) {
		if(!item.hasOwnProperty("needChange")) {
			//基本元素
			if(item.hasOwnProperty("object")) {
				usew += item.object.offsetWidth
			} else if(item.hasOwnProperty("id")) {
				usew += document.getElementById(item.id).offsetWidth
			} else {
				console.error("measureWidth=>元素必须具有id或者object")
				return
			}
		} else {
			needChange.push(item)
			if(!item.hasOwnProperty("weight")) {
				item.weight = 1
			}
			totalWeight += item.weight
		}
	})
	//剩余可用宽度
	var sy = maxWidth - usew
	//开始均分
	needChange.forEach(function(item) {
		var object = {}
		if(item.hasOwnProperty("object")) {
			object = item.object
		} else if(item.hasOwnProperty("id")) {
			object = document.getElementById(item.id)
		} else {
			console.error("measureWidth=>元素必须具有id或者object")
			return
		}
		object.style.width = (parseInt(sy * (item.weight / totalWeight))) + "px"
	})
}
/**
 * 为所有元素均分高度
 * @param {Object} maxHeight 最大高度
 * @param {Object} sons 需要修改宽度的子元素,id字段或者object对象二选一,具有字段needChange的是会变的,weight为权重
 */
function measureHeight(maxHeight, sons) {
	//已经用了的高度
	var useh = 0
	var needChange = []
	var totalWeight = 0
	sons.forEach(function(item) {
		if(!item.hasOwnProperty("needChange")) {
			//基本元素
			if(item.hasOwnProperty("object")) {
				useh += item.object.offsetHeight
			} else if(item.hasOwnProperty("object")) {
				useh += document.getElementById(item.id).offsetHeight
			} else {
				console.error("measureHeight=>元素必须具有id或者object")
				return
			}
		} else {
			needChange.push(item)
			if(!item.hasOwnProperty("weight")) {
				item.weight = 1
			}
			totalWeight += item.weight
		}
	})
	//剩余可用宽度
	var sy = maxHeight - useh
	//开始均分
	needChange.forEach(function(item) {
		var object = {}
		if(item.hasOwnProperty("object")) {
			object = item.object
		} else if(item.hasOwnProperty("id")) {
			object = document.getElementById(item.id)
		} else {
			console.error("measureHeight=>元素必须具有id或者object")
			return
		}
		object.style.height = (parseInt(sy * (item.weight / totalWeight) - 1)) + "px"
	})
}
/**
 * 电量转减排碳量,单位是千瓦时和吨
 * @param {Object} kwh
 */
function powerTranToCO2(kwh) {
	return parseFloat(kwh) * 0.997 / 1000
}
/**
 * 把树形转换为列表,除了第一级每一级都有
 * @param {Object} tree
 * @param {Object} nextkey:下一级的字段
 * @param {Object} isgroup:判断是否继续下一级的方法
 */
function treeToList(tree, nextkey, isgroup) {
	function tranTreeToList(tree, nextkey, isgroup) {
		var list = []
		if(isgroup(tree) && !isempty(tree[nextkey])) {
			tree[nextkey].forEach(function(e) {
				if(isgroup(e)) {
					list = list.concat(tranTreeToList(e, nextkey, isgroup))
				}
				list.push(copy(e))
			})
		}
		return list
	}
	if(nextkey == undefined) {
		nextkey = "next"
	}
	if(isgroup == undefined) {
		isgroup = function(item) {
			return item.hasOwnProperty(nextkey)
		}
	}
	var list = tranTreeToList(tree, nextkey, isgroup)
	list.unshift(copy(tree))
	return list
}
/**
 * 增加菜单
 * @param {Object} menu
 * @param {Object} name
 * @param {Object} url
 */
function addMenu(menu, name, url) {
	menu.push({
		rightname: name,
		webpage: url,
		next: []
	})
	return menu[menu.length - 1].next
}
/**
 * 获取从value0000-value2355的数组
 */
function historyValues() {
	if(historyValues.value != undefined) {
		return historyValues.value
	}
	var list = []
	for(var i = 0; i < 24; i++) {
		for(var j = 0; j < 60; j += 5) {
			list.push('value' + (i < 10 ? '0' : '') + i + (j < 10 ? '0' : '') + j)
		}
	}
	historyValues.value = list
	return list
}
/**
 * 在指定位置插入字符串
 * @param {Object} str表示原字符串变量
 * @param {Object} flg表示要插入的字符串
 * @param {Object} sn表示要插入的位置
 */
function insert_flg(str, flg, sn) {
	var newstr = "";
	for(var i = 0; i < str.length; i += sn) {
		var tmp = str.substring(i, i + sn);
		if(i == sn) {
			newstr += tmp
		} else {
			newstr += tmp + flg
		}
	}
	return newstr;
}

/**
 * 从列表中递归找到指定的对象并且返回,方便修改,返回undefined就是没有
 * @param {Object} list
 * @param {Object} findMethod
 */
function findTreeItem(list, findMethod) {
	for(var i = 0, len = list.length; i < len; i++) {
		var item = list[i]
		if(findMethod(item)) {
			return item
		} else if(!isempty(item.next)) {
			var it = findTreeItem(item.next, findMethod)
			if(it != undefined) {
				return it
			}
		}
	}
}
/**
 * 清除所有缓存并且返回登陆界面
 */
function toLogin() {
	if(debugPage == undefined) {
		return
	}
	localStorage.removeItem("token")
	sessionStorage.removeItem("token")
	// 清除菜单类型 当前菜单的sort 当前用户的usercode本地缓存
	localStorage.removeItem('menuSeparatedState')
	localStorage.removeItem('nowMenuSort')
	localStorage.removeItem('nowWedoSystemUserCode')
	if(debugPage.$dialogMethod != undefined) {
		debugPage.$dialogMethod.closeLoading()
	}
	if(debugPage.$wedoSocketServer != undefined) {
		debugPage.$wedoSocketServer.disConnect()
	}
	if(window.hasOwnProperty("MobileMessage")) {
		MobileMessage.toLogin()
	}
	var keys = Object.keys(debugPage.$store)
	for(var i = 0, len = keys.length; i < len; i++) {
		try {
			if(debugPage.$store[keys[i]].hasOwnProperty('commit')) {
				debugPage.$store[keys[i]].commit("clear")
			}
		} catch(e) {
			err(e.stack)
		}
	}
	debugPage.$router.push("/")
}
/**
 * 添加一个link连接，例如css文件
 */
function addLink(href) {
	var addSign = true;
	var links = document.getElementsByTagName("link");
	for(var i = 0; i < links.length; i++) {
		if(links[i] && links[i].href && links[i].href.indexOf(href) != -1) {
			addSign = false;
		}
	}
	if(addSign) {
		var $link = document.createElement("link");
		$link.setAttribute("rel", "stylesheet");
		$link.setAttribute("type", "text/css");
		$link.setAttribute("href", href);
		document.getElementsByTagName("head").item(0).appendChild($link);
	}
}
/**
 * 移除一个link连接，例如css文件
 */
function removeLink(href) {
	var links = document.getElementsByTagName("link");
	for(var i = 0; i < links.length; i++) {
		var _href = links[i].href;
		if(links[i] && links[i].href && links[i].href.indexOf(href) != -1) {
			links[i].parentNode.removeChild(links[i]);
		}
	}
}

/**
 * 用于同步/异步引入js文件
 */
function ajaxPage(url, sync) {
	var oXmlHttp = GetHttpRequest()
	oXmlHttp.onreadystatechange = function() {
		if(oXmlHttp.readyState == 4) {
			includeJSToHead(oXmlHttp.responseText)
		}
	}
	oXmlHttp.open('GET', url, sync != false)
	oXmlHttp.send(null)
}

function GetHttpRequest() {
	if(window.XMLHttpRequest) // Gecko
		return new XMLHttpRequest()
	else if(window.ActiveXObject) // IE
		return new ActiveXObject("MsXml2.XmlHttp")
}

function includeJSToHead(source) {
	if(source != null) {
		var oScript = document.createElement("script")
		oScript.type = "text/javascript"
		oScript.text = source
		document.getElementsByTagName('HEAD').item(0).appendChild(oScript)
	}
}
//处理url后面的参数变成对象形式
//方法问题  需要修改
function  GetRequest(urlStr) {
	if(typeof urlStr == "undefined") {
		var url = decodeURI(location.search);
	}
	else {
		var url = "?" + urlStr.split("?")[1];
	}
	var theRequest = new Object();
	if(url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
		}
	}
	return theRequest
}